package com.cliff.web;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cliff.common.exception.MyException;

@Controller
public class HelloController {

    @RequestMapping("/")
    public String index(ModelMap map){
        // 加入一个属性，用来在模板中读取
        map.addAttribute("host","www.baidu.com");
       // return模板文件的名称，对应src/main/resources/templates/index.html
        return "index";
    }

//    @RequestMapping("/f")
//    public String index2(ModelMap map){
//        map.addAttribute("host","www.baidu.com");
//        return "index2";
//    }
    
//    @RequestMapping("/v")
//    public String index3(ModelMap map){
//        map.addAttribute("host","www.baidu.com");
//        return "index3";
//    }
    
    @RequestMapping("/hello")
    public String hello(){
        return "Hello World!";
    }
    
    @RequestMapping("/errortest")
    public String errortest() throws Exception {
        throw new Exception("发生错误");
    }
    
    @RequestMapping("/json")
    public String json() throws MyException {
        throw new MyException("发生错误2");
    }

}
